#ifndef FND_GAME_NODE_RECORD_MANAGER_H
#define FND_GAME_NODE_RECORD_MANAGER_H
#include "valuerange.hpp"
#include <vector>
#include <utility>
#include <boost/tuple/tuple.hpp>
#include <bitset>

enum {
    NODE_POSITION,
    NODE_X,
    NODE_Y,
    NODE_ROUND,
} ;

namespace Utility {
    typedef boost::tuple<normal_number_range, float, float, int> node_record_value_type ;
    typedef std::pair<int,node_record_value_type> node_record_type ;

    class node_record_manager {
    public:
        bool write_to_file(const char* file_name) ;
        bool read_from_file(const char* file_name) ;
        void push_record(const node_record_value_type& v) ;
        void add_record(int id, const node_record_value_type& v) ;
        void push_record(const normal_number_range& value, float x, float y, int level = 0) ;
        void add_record(int id, const normal_number_range& value, float x, float y, int level = 0) ;
        void remove_range(int idbegin, int idend) ;
        void conbine_records(const node_record_manager& other) ;
        void rerange() ;
        void remove_record(int id) ;
        node_record_value_type& node_info(int id) ;
        node_record_manager() ;
        size_t size() const {return m_records.size() ;}
        // add this for info manager
        const node_record_value_type& operator[](size_t pos) const {
            return m_records[pos].second ;
        }
    private:
        typedef std::vector<node_record_type> manager_record_vector ;
        typedef std::bitset<12000> record_bits_type ;
        record_bits_type m_record_bits ;
        manager_record_vector m_records ;
        int m_valid_record_id ;
        void make_value_valid(manager_record_vector::reference value) ;
        void buy_record_from_other(const node_record_type& node) ;
        bool need_remove(const node_record_type& node) ;
        
    } ;

   
}

inline bool operator == (const Utility::node_record_type& lhs,
                         const Utility::node_record_type& rhs) {
    return lhs.first == rhs.first ;
}

inline bool operator < (const Utility::node_record_type& lhs,
                        const Utility::node_record_type& rhs) {
    return lhs.first < rhs.first ;
}

#endif
